jQuery(() => {
    $("#btnLogin").on("click", function () {
        const cs = new CookieSettings();

        let usr = $("#username").val();
        let pass = $("#password").val();
        let acttype = $("#acttype").val();

        if (!pass || 0 === pass.length) {
            alert("密码不能为空！");
            cs.writeCookie("loginstatus", "", 2);
            return;
        }

        if (!usr || 0 === usr.length) {
            alert("用户名不能为空！");
            cs.writeCookie("loginstatus", "", 2);
            return;
        }

        let formData = new FormData();

        formData.append("username", usr);
        formData.append("password", pass);

        $.ajax({
            url: apiurl + '/sys/user/login',
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false
        }).done(function (res) {
            if (typeof res.username === 'string') {
                if (res.username.trim().length > 0) {
                    cs.writeCookie("loginstatus", "T|" + res.username.trim(), 2);
                    window.location.href = "/index.html";
                }
            }
        }).fail(function (res) {
        });
    });
});